$(function () {
    var options = {
        modalName: "订单",
        url: "/render/orderManager/list",
        getInfoUrl: "/render/orderManager/get/{id}",
        updateUrl: "/render/orderManager/edit",
        removeUrl: "/render/orderManager/remove",
        createUrl: "/render/orderManager/add",
        searchUrl: "/render/orderManager/search",
        pageNumber:1,
        pageSize:7,
        columns: [
            {
                checkbox: true,
                formatter:checkboxMatter
            }, {
                field: 'user_id',
                title: 'ID',
                align: "center",
                width: '50px',
                class:"colStyle",
                sortable : true,
                cellStyle:formatTableUnit,
                formatter:paramsMatter
            }, {
                field: 'order_no',
                title: '订单号',
                align: "center",
                width: '140px',
                sortable : true,
                cellStyle:formatTableUnit,
                formatter:paramsMatter
            }, {
                field: 'shipping_id',
                title: '快递单',
                align: "center",
                width: '60px',
                sortable : true,
                cellStyle:formatTableUnit,
                formatter:paramsMatter
            }, {
                field: 'payment',
                title: '付款额',
                align: "center",
                width: '60px',
                sortable : true,
                cellStyle:formatTableUnit,
                formatter:paramsMatter
            }, {
                field: 'payment_type',
                title: '支付类型',
                align: "center",
                width: '100px',
                sortable : true,
                cellStyle:formatTableUnit,
                formatter:paramsMatter
            }, {
                field: 'status',
                title: '状态',
                align: "center",
                width: '50px',
                sortable : true,
                cellStyle:formatTableUnit,
                // formatter:paramsMatter
                formatter: function (value) {
                    if (value == 10) {
                        value = '未付款'
                    }

                    if (value == 20){
                        value = '付款';
                    }

                    var span=document.createElement('span');
                    span.setAttribute('title',value);
                    span.innerHTML = value;
                    return span.outerHTML;
                }
            }, {
                field: 'payment_time',
                title: '支付时间',
                align: "center",
                width: '88px',
                sortable : true,
                cellStyle:formatTableUnit,
                formatter:paramsMatter
            }, {
                field: 'send_time',
                title: '发货时间',
                align: "center",
                width: '88px',
                sortable : true,
                cellStyle:formatTableUnit,
                formatter:paramsMatter
            }, {
                field: 'operate',
                title: '操作',
                align: "center",
                width: '150px',
                //自定义方法，添加操作按钮
                formatter: function operateFormatter(code, row) {
                    var trId = row.id;
                    var trOrderNo = row.order_no;
                    // console.log("trOrderNo="+trOrderNo);
                    var operateBtn = [
                        '<a class="btn btn-sm btn-info btn-push" id="btn-push" data-id="' + trOrderNo + '" title="详情"><i class="fa fa-send-o fa-fw"></i></a>',
                        '<a class="btn btn-sm btn-success btn-update" data-id="' + trId + '" title="编辑"><i class="fa fa-edit fa-fw"></i></a>',
                        '<a class="btn btn-sm btn-danger btn-remove" data-id="' + trId + '" title="删除"><i class="fa fa-trash-o fa-fw"></i></a>'
                    ];
                    return operateBtn.join('');
                }
                /**/
            }
        ]
    };
    // 初始化table组件
    var table = new Table(options);
    table.init();

    //search按钮绑定查询事件
    $('#btnSearch').on('click', function () {
        var searchtext = {
            user_id: $("#search-user_id").val(),
            order_no: $("#search-order_no").val(),
            status: $("#search-status").val()
        };
        // console.log(""+$("#search-name").val());
        if($("#search-user_id").val() === ""&&$("#search-order_no").val() === ""&&$("#search-status").val() === ""){
            postParams(options.url,options.onExpandRow,options,options.rowStyle,options.columns,null,true);
        }else {
            postParams(options.searchUrl,options.onExpandRow,options,options.rowStyle,options.columns,JSON.stringify(searchtext),false);
        }
    });

    $(".close,.btn-default").on("click",function () {
        $(".modal").css("display","");
        $(".modal").removeClass("in");
        $(".modal-backdrop").removeClass("in");
    });
});


/*
, {
    field: 'postage',
        title: '运费',
        align: "center",
        width: '50px',
        cellStyle:formatTableUnit,
        formatter:paramsMatter
}
, {
    field: 'id',
    title: '订单ID',
    align: "center",
    width: '50px',
    class:"colStyle",
    sortable : true,
    formatter:paramsMatter
}
, {
    field: 'end_time',
    title: '交易完成时间',
    align: "center",
    width: '88px',
    sortable : true,
    cellStyle:formatTableUnit,
    formatter:paramsMatter
}
*/
